//
//  ShoppingCartTableViewCell.m
//  JiuJiuShangCheng
//
//  Created by jiujiukeji on 2018/7/4.
//  Copyright © 2018年 jiujiukeji. All rights reserved.
//

#import "ShoppingCartTableViewCell.h"

@implementation ShoppingCartTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUpUI];
    }
    return self;
}
#pragma mark - 修改删除滑块颜色（小于ios11）
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    for (UIView *subView in self.subviews) {
        if ([NSStringFromClass([subView class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
            ((UIView *)[subView.subviews firstObject]).backgroundColor = navBarColor;
        }
    }
}
- (void)setUpUI
{
    WeakSelf
    
    self.selectBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.selectBtn setImage:UIImageNamed(@"shemoren") forState:(UIControlStateNormal)];
    [self addSubview:_selectBtn];
    [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.size.mas_offset(CGSizeMake(rateWidth(80), rateHeight(180)));
        make.centerY.equalTo(self);
    }];
    
    self.goodsImg = [[UIImageView alloc] init];
    _goodsImg.image = UIImageNamed(@"goodsimg");
    [self addSubview:_goodsImg];
    [_goodsImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.selectBtn.mas_right);
        make.centerY.equalTo(self);
        make.size.mas_offset(CGSizeMake(rateHeight(180), rateHeight(180)));
    }];
    
    self.goodsNameLB = [UILabel labelWithText:@"" textColor:UIColorFromRGB(0x333333) fontSize:15];
    [_goodsNameLB sizeToFit];
    _goodsNameLB.numberOfLines = 0;
    [self addSubview:_goodsNameLB];
    [_goodsNameLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.goodsImg);
        make.left.equalTo(weakSelf.goodsImg.mas_right).offset(rateWidth(25));
        make.width.mas_lessThanOrEqualTo(@(rateWidth(390)));
        make.height.mas_lessThanOrEqualTo(@(rateHeight(80)));
    }];
    
    self.describeLB = [UILabel labelWithText:@"已选：“90%”“红色”" textColor:UIColorFromRGB(0x666666) fontSize:13];
    _describeLB.numberOfLines = 0;
    [_describeLB sizeToFit];
    [self addSubview:_describeLB];
    [_describeLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.goodsNameLB.mas_bottom).offset(rateHeight(20));
        make.left.equalTo(weakSelf.goodsNameLB);
        make.width.mas_lessThanOrEqualTo(@(rateWidth(390)));
        make.height.mas_lessThanOrEqualTo(@(rateHeight(50)));
    }];
    
    self.priceLB = [UILabel labelWithText:@"" textColor:UIColorFromRGB(0xf55555) fontSize:15];
    [_priceLB sizeToFit];
    [self addSubview:_priceLB];
    [_priceLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.goodsNameLB);
        make.bottom.equalTo(weakSelf.goodsImg);
    }];
    
    self.doneNumLB = [UILabel labelWithText:@"×1" textColor:UIColorFromRGB(0x666666) fontSize:13];
    [_doneNumLB sizeToFit];
    [self addSubview:_doneNumLB];
    [_doneNumLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.priceLB);
        make.right.equalTo(self).offset(-rateWidth(50));
    }];
    
    self.editImg = [[UIImageView alloc] init];
    _editImg.image = UIImageNamed(@"numEditImg");
    [_editImg sizeToFit];
    [self addSubview:_editImg];
    [_editImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-rateWidth(30));
        make.bottom.equalTo(self).offset(-rateHeight(30));
    }];
    _editImg.userInteractionEnabled = YES;
    
    self.numLB = [UILabel labelWithText:@"1" textColor:UIColorFromRGB(0x666666) fontSize:13];
    [_numLB sizeToFit];
    [_editImg addSubview:_numLB];
    [_numLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakSelf.editImg);
    }];
    
    self.jiaBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self addSubview:_jiaBtn];
    [_jiaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30, 50));
        make.centerX.equalTo(weakSelf.editImg.mas_right);
        make.centerY.equalTo(weakSelf.editImg);
    }];
    self.jianBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self addSubview:_jianBtn];
    [_jianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30, 50));
        make.centerX.equalTo(weakSelf.editImg.mas_left);
        make.centerY.equalTo(weakSelf.editImg);
    }];
    _editImg.hidden = YES;
    _jiaBtn.hidden = YES;
    _jianBtn.hidden = YES;
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = globalGray;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.equalTo(@(rateHeight(2)));
    }];
}

@end
